package com.ciis.system.module.controller;

import com.ciis.base.page.IPage;
import com.ciis.base.page.Page;
import com.ciis.system.module.domain.ModuleMenuTree;
import com.ciis.system.module.domain.TSysModule;
import com.ciis.system.module.service.ISysModuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: zhangdajun
 * Date: 14-6-19
 * Time: 下午8:42
 * To change this template use File | Settings | File Templates.
 */
@RequestMapping("/module")
@Controller
public class SysModuleController {

    @Autowired
    ISysModuleService sysModuleService;

    @RequestMapping(value="/save",method = RequestMethod.POST)
    @ResponseBody
    private boolean saveModule(TSysModule sysModule) throws Exception{
        try{
            sysModuleService.save(sysModule);
        }catch(Exception ex){
            ex.printStackTrace();
            return false;
        }
        return true;
    }

    @RequestMapping(value="/getModulePage/{id}",method = RequestMethod.GET)
    @ResponseBody
    public IPage<TSysModule> getModulePage(TSysModule module) throws Exception{
        Page pager = new Page();
        //pager.setPage(10);
        return sysModuleService.findPage(pager,module);
    }

    @RequestMapping(value="/getModuleMenu",method = RequestMethod.GET)
    @ResponseBody
    public ModuleMenuTree getModuleMenu(String pId) throws Exception{
        return sysModuleService.findModuleTreeByPid(pId);
    }

    @RequestMapping(value="/getRootMenu",method = RequestMethod.GET)
    @ResponseBody
    public List<TSysModule> getModuleMenuByLevel(@RequestParam(value="level",required = false,defaultValue = "0")String level) throws Exception{
        return sysModuleService.findModuleListByLevel(level);
    }

}
